package edu.tyut.game.dao.game;

import edu.tyut.game.model.FlyingFlowerOrderData;
import edu.tyut.game.model.UserTotalRoundsRank;
import edu.tyut.game.model.UserWinRateRank;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface FlyingFlowerOrderDao {
    /**
     * 目的很简单，根据胜率，总局数匹配对手
     * @param uid 用户id
     * @return 返回用户飞花令游戏数据
     */
    @Select("select * from db_game.tb_fly_flower_order where uid = #{uid}")
    FlyingFlowerOrderData getUserDataByUid(int uid);

    @Insert("insert into tb_fly_flower_order(uid, win_rate, win_rounds, total_rounds) values (#{uid}, 0, 0, 0)")
    void insertData(int uid);

    @Update("update tb_fly_flower_order set win_rate = #{winRate},  win_rounds = #{winRounds}, total_rounds = #{totalRounds} where uid = #{uid}")
    int updateData(FlyingFlowerOrderData data);

    @Select("select content from tb_poem where content like CONCAT('%', #{word}, '%')")
    List<String> getContentsByWord(String word);

    // 获取胜率前十名数据
    @Select("select username, tb_user.avatar_path, fly.win_rate from tb_user , tb_fly_flower_order as fly where tb_user.id = fly.uid order by win_rate DESC limit 5")
    @Results({
            @Result(property = "avatarPath", column = "avatar_path"),
            @Result(property = "winRate", column = "win_rate"),
    })
    List<UserWinRateRank> getWinRateRank();
    // 获取总局数前十名数据
    @Select("select username, tb_user.avatar_path, fly.total_rounds from tb_user , tb_fly_flower_order as fly where tb_user.id = fly.uid order by total_rounds DESC limit 5 ;")
    @Results({
            @Result(property = "avatarPath", column = "avatar_path"),
            @Result(property = "totalRounds", column = "total_rounds"),
    })
    List<UserTotalRoundsRank> getTotalRoundsRank();
}
